﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace AgentBar.Common
{
    public class PicBoxStatus
    {
        public string Title { get; set; }
        public Image BackGroudImage { get; set; }
        public PictureBox PictureBox { get; set; }
        public bool Enabled { get; set; }
    }

    public class PictureBoxTool
    {
        public static void DrawPictureBoxList(List<PicBoxStatus> ListPicBox)
        {
            PicBoxStatus picBox = new PicBoxStatus();
            foreach (var item in ListPicBox)
            {
                DrawInPictureBox(item);
            }
        }

        public static void DrawInPictureBox(PicBoxStatus status)
        {
            if (status == null) return;
            Bitmap bmp = new Bitmap(status.BackGroudImage);
            int fontSize = 8;
            SolidBrush mycolor;
            if(status.Enabled)
                mycolor = new SolidBrush(Color.Black);
            else
                mycolor = new SolidBrush(Color.White);
            if (status.PictureBox.Name == "PicStatus")
            {
                fontSize = 12;
                mycolor = new SolidBrush(Color.White);
            }
            Font drawfont = new Font("MS UI Gothic", fontSize, FontStyle.Regular);
            Graphics g = Graphics.FromImage(bmp);
            SizeF sizeF = new SizeF(g.MeasureString(status.Title, drawfont));
            int X = (int)(status.PictureBox.Width - sizeF.Width) / 2;
            int Y = (int)(status.PictureBox.Height - sizeF.Height) / 2;
            g.DrawString(status.Title, drawfont, mycolor, X,Y);
            status.PictureBox.BackgroundImage = bmp;
            g.Dispose();
            status.PictureBox.Enabled = status.Enabled;
        }
    }
}
